/*
 * 
 * 织梦版微信小程序
 * author: 鹏厄
 * 小镇故事66UI.com
 */
import config from 'config.js';
var domain = config.getDomain;
var pageCount = config.getPageCount;
var categoriesID = config.getCategoriesID;
var indexListType = config.getIndexListType;
var HOST_URI = 'https://' + domain +'/plus/wxjson-Open/';
   
module.exports = {  
  // 获取首页文章列表数据
  getPosts: function (obj) {
    var url = HOST_URI + '?action=index&indexFlag=c&page=' + obj.page;
    if (obj.categories != 0) {
      url += '&categories=' + obj.categories;
    }
    else if (obj.search != '') {
      url = HOST_URI + '?action=search&q=' + encodeURIComponent(obj.search);
    }
    else{
        if (indexListType !='all')
        {
          url += '&categories=' + indexListType;
        }
    }     
    return url;
  },

 //获取文章列表数据
  getList: function (obj) {
    var url = HOST_URI + '?action=list&indexFlag=&page=' + obj.page;
    if (obj.categories != 0) {
      url += '&categories=' + obj.categories;
    }
    else if (obj.search != '') {
      url = HOST_URI + '?action=search&q=' + encodeURIComponent(obj.search);
    }
    else {
      if (indexListType != 'all') {
        url += '&categories=' + indexListType;
      }
    }
    return url;
  },

  // 获取推荐文章列表数据
  getPostsTopic: function (obj) {
    var url = HOST_URI + '?action=topic&typeid=&indexFlag=h&page=' + obj.page;
    return url;

  },

  
  // 获取多个分类文章列表数据
  getPostsByCategories: function (categories) {
      var url = HOST_URI + 'posts?per_page=20&orderby=date&order=desc&page=1&categories=' + categories;
      return url;
  },
// 获取置顶的文章
  getStickyPosts: function () {
    var url = HOST_URI + 'posts?sticky=true&per_page=5&page=1';
    return url;

  },
 
  
  //获取首页滑动文章
  getSwiperPosts: function () {
    var url = HOST_URI+'/swipe.php';
      return url;
  },

  //获取是否开启评论的设置
  getEnableComment: function () {
    var url = HOST_URI + '?action=setFeedback&enableComment=1';
    return url;
  },

  // 获取tag相关的文章列表
  getPostsByTags: function (id,tags) {
    var url = HOST_URI + '?action=LikeList&id=' + id + '&tags=' + tags+'';
    return url;

  },

  // 获取特定id的文章列表
  getPostsByIDs: function (obj) {
    var url = HOST_URI + 'posts?include=' + obj;

    return url;

  },
  // 获取特定slug的文章内容
  getPostBySlug: function (obj) {
      var url = HOST_URI + 'posts?slug=' + obj;
      
      return url;

  },
  // 获取内容页数据
  getPostByID: function (id) {
    var url = HOST_URI + '?action=view&id=' + id;
    return url;
  },
  // 获取页面列表数据
  getPages: function () {
    
    return HOST_URI + 'pages';
  },

  // 获取页面列表数据
  getPageByID: function (id, obj) {
    return HOST_URI + 'pages/' + id;
  },
  //获取分类列表
  getCategories: function () {
    var  url = HOST_URI + '?action=category';
    return url
  },
  //获取某个分类信息
  getCategoryByID: function (id) {
    var url = HOST_URI + '?action=arctype&typeid='+id;
    return url;
  },
  //获取某文章评论
  getComments: function (obj) {
    var url = HOST_URI + '?action=feedback&post=' + obj.postID + '&page=' + obj.page;
    return url;
  },

  //获取文章评论及其回复
  getCommentsReplay: function (obj) {
    var url = HOST_URI + '?action=setFeedback&getcomments=1&arcid=' + obj.postId + '&page=' + obj.page;
    return url;
  },
  //获取网站的最新20条评论
  getNewComments: function () {
      return HOST_URI + 'comments?parent=0&per_page=20&orderby=date&order=desc';
  },

  //获取回复
  getChildrenComments: function (obj) {
    var url= HOST_URI + 'comments?parent_exclude=0&per_page=100&orderby=date&order=desc&post=' + obj.postID
     return url;
  },  //获取最近的30个评论
  getRecentfiftyComments:function(){
    return HOST_URI + 'comments?per_page=30&orderby=date&order=desc'
  },

  //提交评论
  postComment: function () {
    return HOST_URI + 'comments'
  }, 

  //提交微信评论
  postWeixinComment: function () {
    var url = HOST_URI + '?action=setFeedback&postWeixinComment=1';
    return url;
  }, 

  //获取微信评论
  getWeixinComment: function (mid) {
    var url = HOST_URI + '?action=myfeedback&userid=' + mid;
    return url;
  },

  //获取文章的第一个图片地址,如果没有给出默认图片
  getContentFirstImage: function (content){
    var regex = /<img.*?src=[\'"](.*?)[\'"].*?>/i;
    var arrReg = regex.exec(content);
    var src ="../../images/logo700.png";
    if(arrReg){   
      src=arrReg[1];
    }
    return src;  
  },

 //获取热点文章
  getTopHotPosts(flag){      
    var url = HOST_URI;
      if(flag ==1)
      {
        url += '?action=hot&typeid=&hotType=click&page=1';
    } 
      else if(flag==2)
      {
        url += '?action=hot&typeid=&hotType=goodpost&page=1';
      }
      
      return url;
  },

  //更新文章浏览数
  updatePageviews(id) {
      var url = HOST_URI_WATCH_LIFE_JSON;
      url += "post/addpageview/"+id;
      url = HOST_URI + '?view=yes&mid=1&aid=' + id;
      return url;
  },
  //获取用户openid
  getOpenidUrl() { 
    var url = HOST_URI + '?action=getopenid';
  return url;
  },
  

   //更新用户信息
   getUpdateUserInfo() {
    var url = HOST_URI + '?action=updateuserinfo';

    return url;
  },

  //收藏
  setFavoriteUrl() {
    var url = HOST_URI + '?action=setFavorite';
    return url;
  },  //点赞
  postLikeUrl() {
    var url = HOST_URI + '?action=like';
    return url;
  },

  //判断当前用户是否点赞
  postIsLikeUrl() {
    var url = HOST_URI + '?action=islike';
    return url;
  },

  //获取我的收藏
  getMyFavorite(mid) {
    var url = HOST_URI + '?action=myfavorite&userid=' + mid;
    return url;
  },  //获取我的点赞
  getMyLikeUrl(mid) {
    var url = HOST_URI + '?action=myLike&userid=' + mid;
      return url;
  },

  //鼓励,获取支付密钥
  postPraiseUrl() { 
    var url = HOST_URI_WATCH_LIFE_JSON;  
    url += "payment";
    return url;
  },

  //更新鼓励数据
  updatePraiseUrl() {
    var url = HOST_URI_WATCH_LIFE_JSON;
    url += "post/praise";
    return url;
  },

  //获取我的鼓励数据
  getMyPraiseUrl(openid) {
      var url = HOST_URI_WATCH_LIFE_JSON;
      url += "post/mypraise?openid=" + openid;
      return url;
  },

  //获取所有的鼓励数据
  getAllPraiseUrl() {
      var url = HOST_URI_WATCH_LIFE_JSON;
      url += "post/allpraise";
      return url;
  },

  //发送模版消息
  sendMessagesUrl() {
      var url = HOST_URI_WATCH_LIFE_JSON;
      url += "weixin/sendmessage";
      return url;
  },
  //获取订阅的分类
  getSubscription() {
      var url = HOST_URI_WATCH_LIFE_JSON;
      url += "category/getsubscription";
      return url;
  },

  //订阅的分类
  postSubscription() {
      var url = HOST_URI_WATCH_LIFE_JSON;
      url += "category/postsubscription";
      return url;
  },

  //删除订阅的分类
  delSubscription() {
      var url = HOST_URI_WATCH_LIFE_JSON;
      url += "category/delSubscription";
      return url;
  },

  //生成海报
  creatPoster() {
      var url = HOST_URI + '?action=qrcodeimg';
      return url;
  },
  //获取海报
  getPosterUrl() {
      var url = 'https://' + domain + "/wp-content/plugins/rest-api-to-miniprogram/poster/";
      return url;
  },
  //获取二维码
  getPosterQrcodeUrl() {
      var url = 'https://' + domain + "/wp-content/plugins/rest-api-to-miniprogram/qrcode/";
      return url;
  }
};